/*
 * Test_FindAndUnion.cpp
 *
 *  Created on: Apr 4, 2014
 *      Author: zby
 */

#include "FindAndUnion.h"
#include "Test_FindAndUnion.h"

CppUnit::Test* Test_FindAndUnion::suite(){
    CppUnit::TestSuite* suiteOfTests = new CppUnit::TestSuite("Test_Board");
    suiteOfTests->addTest(new CppUnit::TestCaller<Test_FindAndUnion>("test_def_constructor",&Test_FindAndUnion::test_def_constructor));
    suiteOfTests->addTest(new CppUnit::TestCaller<Test_FindAndUnion>("test_def_constructor",&Test_FindAndUnion::test_unite));
    suiteOfTests->addTest(new CppUnit::TestCaller<Test_FindAndUnion>("test_def_constructor",&Test_FindAndUnion::test_root));
    suiteOfTests->addTest(new CppUnit::TestCaller<Test_FindAndUnion>("test_def_constructor",&Test_FindAndUnion::test_ifTheSameRoot));

    return suiteOfTests;
}

void Test_FindAndUnion::test_def_constructor(void)
{
    CPPUNIT_ASSERT(0==fau->id[0] && 1==fau->id[1] && 2==fau->id[2] && 9==fau->id[9]);
}

void Test_FindAndUnion::test_unite(void)
{
    //connect: true:
    // 0->1
    // 8->9
    // 2->1
    // 0->9
    CPPUNIT_ASSERT(true==fau->unite(0,1) &&  true==fau->unite(8,9) && true==fau->unite(2,1) &&
            true==fau->unite(0,9));
    //connect: false(the same root):
    // 2->8
    CPPUNIT_ASSERT(false==fau->unite(2,8) && false ==fau->unite(9,8) && false==fau->unite(9,9) &&
                   false==fau->unite(0,0));
}

void Test_FindAndUnion::test_root(void)
{
    //connect:
    //5->4
    //4->3
    //3->2
    //5->0
    //6->7
    //7->8
    //6->9
    fau->unite(5,4);fau->unite(4,3);fau->unite(3,2);fau->unite(5,0);
    fau->unite(6,7);fau->unite(7,8);fau->unite(6,9);
    CPPUNIT_ASSERT(0==fau->root(5) && 9==fau->root(6) && 0==fau->root(0) && 9==fau->root(9));
    //connect:
    //0->9
    fau->unite(0,9);
    CPPUNIT_ASSERT(9==fau->root(0) && 9==fau->root(5) && 9==fau->root(6));
}

void Test_FindAndUnion::test_ifTheSameRoot(void)
{
    //connect:
    //5->4
    //4->3
    //3->2
    //5->0
    //6->7
    //7->8
    //6->9
    fau->unite(5,4);fau->unite(4,3);fau->unite(3,2);fau->unite(5,0);
    fau->unite(6,7);fau->unite(7,8);fau->unite(6,9);
    CPPUNIT_ASSERT(true==fau->ifTheSameRoot(5,0) && true==fau->ifTheSameRoot(6,9) && false==fau->ifTheSameRoot(0,9));
}
